package com.xyzwps.server.paimon.common

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.*

@Suppress("ConstantValue")
class UtilsTests {

    @Test
    fun testMask() {
        // Normal case: masking in the middle of the string
        assertEquals("123****890", Utils.mask("1234567890", 3, 4, '*'))

        // Boundary case: start is 0
        assertEquals("****567890", Utils.mask("1234567890", 0, 4, '*'))

        // Boundary case: start exceeds string length
        assertEquals("1234567890", Utils.mask("1234567890", 15, 4, '*'))

        // Boundary case: length exceeds remaining length
        assertEquals("123*******", Utils.mask("1234567890", 3, 20, '*'))

        // Special case: empty string
        assertEquals("", Utils.mask("", 3, 4, '*'))
    }

    @Test
    fun testMaskWithInvalidArguments() {
        // Test case where start is negative
        assertThrows(IllegalArgumentException::class.java) { Utils.mask("1234567890", -1, 4, '*') }

        // Test case where length is negative
        assertThrows(IllegalArgumentException::class.java) { Utils.mask("1234567890", 3, -1, '*') }

        // Test case where both start and length are negative
        assertThrows(IllegalArgumentException::class.java) { Utils.mask("1234567890", -1, -1, '*') }
    }

    @Test
    fun testMaskPhone() {
        // Test phone number masking functionality
        assertEquals("138****5678", Utils.maskPhone("13812345678"))
        assertEquals("138***", Utils.maskPhone("138123"))
        assertEquals("138****567890", Utils.maskPhone("1381234567890"))
        assertEquals("", Utils.maskPhone(""))
    }

    @Test
    fun testRepeat() {
        // Normal case
        assertEquals("*****", Utils.repeat('*', 5))
        assertEquals("aaaaaaaa", Utils.repeat('a', 8))

        // Boundary case: repeat 0 times
        assertEquals("", Utils.repeat('*', 0))

        // Boundary case: repeat 1 time
        assertEquals("*", Utils.repeat('*', 1))
    }

    @Test
    fun testIsEmptyString() {
        // Normal case: empty string
        assertTrue(Utils.isEmpty(""))

        // Normal case: null
        assertTrue(Utils.isEmpty(null as String?))

        // Normal case: non-empty string
        assertFalse(Utils.isEmpty("test"))

        // Boundary case: string with only spaces
        assertFalse(Utils.isEmpty(" "))
    }
}
